/**
 * 
 */
package com.slink.fxfk.demo.domain.po;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * @author 新
 *
 */
@Entity
@Table(name = "tb_teacher")
public class PTeacher {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	@Column(unique = true, name = "t_name")
	private String name;
	
	// 课程-老师关系 一对一
	@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REFRESH })
	// 为保证在数据库中也是一对一的关系，@JoinColumn需要声明为unique属性为true，
	// 利用数据库的unique约束保证代课老师的唯一性
	@JoinColumn(name = "course_id", unique = true)
	// 外键为 course_id
	private PCourse course;
	
	/**
	 * 一对多关系（一个老师可以带多门副课）
	 * mappedBy 使用反向配置，指定具体配置在对方实体，即Course的teacher属性
	 */
	@OneToMany(mappedBy="teacher", cascade=CascadeType.PERSIST)
	
	private Set<PCourse> courses = new HashSet<PCourse>();
	
	public PCourse getCourse() {
		return course;
	}

	public void setCourse(PCourse course) {
		this.course = course;
	}

	public Set<PCourse> getCourses() {
		return courses;
	}

	public void setCourses(Set<PCourse> courses) {
		this.courses = courses;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
